package com.example.xinhuazidian.base

import com.google.gson.TypeAdapter
import okhttp3.ResponseBody
import retrofit2.Converter
import java.io.IOException

/**
 * Describe : 重写ResponseBodyConverter对json预处理
 */
class BaseResponseBodyConverter<T> internal constructor(private val adapter: TypeAdapter<out Any>) :
    Converter<ResponseBody, T> {
    @Throws(IOException::class)
    override fun convert(value: ResponseBody): T? {
        val jsonString = value.string()
        //正确返回整个json
        return adapter.fromJson(jsonString) as T?
    }
}